package gindemo

import (
	"context"
	"fmt"
	"github.com/gin-gonic/gin"
	"github.com/opentracing/opentracing-go"
	"net/http"
	"time"
)

func initRouter(enginer *gin.Engine)  {
    enginer.StaticFS("/static",http.Dir("static"))
	enginer.GET("/a1", func(c *gin.Context) {

		beforTime:=time.Now().String()

		time.Sleep(time.Second*1)

		value, _ := c.Get("ctx")
		ctx := value.(context.Context)

		span, _ := opentracing.StartSpanFromContext(ctx, "/a1请求数据库")
		span.SetTag("message","success")
		time.Sleep(time.Second*3)
		span.Finish()

		span1, _ := opentracing.StartSpanFromContext(ctx, "/a1调用外部数据")
		fmt.Println("========middle")
		time.Sleep(time.Second*2)
		span1.SetTag("message","error")
		span1.Finish()

		c.JSON(200,gin.H{"a1":beforTime + "get啊的值"+time.Now().String()})
	})

	v1:=enginer.Group("v1")
	v1.Use(v1middle_1,v1middle_2)
	{
		v1.GET("/a2",v1get)
		v1.GET("/config",v1Config)
	}

	v2:=enginer.Group("v2")

	 //8M 8*1024*1024
	v2.Use(RateLimitMiddleware(1))
	{
		v2.GET("testQos",QosVC)
		v2.POST("single",SigleFileUplad)
		v2.POST("mul",MulFileUplad)
		v2.GET("down",FileDown)
	}



}
